<template>
  <!-- 我的下级 -->
  <div class="form-box">
    <el-table :data="list" stripe border>
      <el-table-column label="入金" prop="inCashMoney" min-width="40%" align="center" />
      <el-table-column label="出金" prop="outCashMoney" min-width="40%" align="center" />
    </el-table>

    <div class="item-box" v-for="(item,index) in allList" :key="index">
      <div class="item">
        <div>{{item.name}}:</div>
        <div class="value">{{item.value}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserAssets, getOrderResellDetail } from "@/api/vip/vip";
// 入金总和、出金总和、累计纯收益、现金余额、金积分余额、银积分余额、消费券余额、佣金余额、
export default {
  name: 'formProfit',
  props: {
    queryParams: {
      type: Object,
    },
  },

  data() {
    return {
      loading: false,
      list: [],
      allList: [
        { name: '佣金余额', value: '' },
        { name: '佣金总入', value: '' },
        { name: '现金余额', value: '' },
        { name: '冻结金', value: '' },
        { name: '金积分余额', value: '' },
        { name: '银积分余额', value: '' },
        { name: '消费券余额', value: '' },
        { name: '转售中(转卖后价格)', value: '' },
        { name: '转售中(买入价格)', value: '' },
        { name: '已付款未转卖', value: '' },
        // { name: '累计收益', value: '' },
        { name: '累计现金收益', value: '' },
        { name: '累计消费券收益', value: '' },
      ],
    }
  },

  created() {
    this.getList();
  },

  methods: {
    async getList() {
      this.loading = true;
      this.queryParams.id = this.queryParams.userId;

      getUserAssets(this.queryParams).then((response) => {
        if (response.code == 200) {
          let data = response.data;
          this.list.push({ 'inCashMoney': data.inMoney, 'outCashMoney': data.outMoney });
          let outCashMoney = data.outMoney; //出金
          let inCashMoney = data.inMoney; //入金
          // let outBrokerageMoney = data.brokerageInOut&&data.brokerageInOut.outMoney?data.brokerageInOut.outMoney:0; //出金
          let inBrokerageCashMoney = data.brokerageInOut&&data.brokerageInOut.inMoney?data.brokerageInOut.inMoney:0; //入金
          let brokerageAmount = data.brokerage && data.brokerage.brokerageAmount ? data.brokerage.brokerageAmount : 0; //佣金余额
          let cashAmount = data.cash && data.cash.cashAmount ? data.cash.cashAmount : 0; //现金余额
          // let brokerageAmount =data.cash? data.cash.brokerageAmount:0; //累计收益
          let goldAmount = data.integral && data.integral.goldAmount ? data.integral.goldAmount : 0; //金积分余额
          let silverAmount = data.integral && data.integral.silverAmount ? data.integral.silverAmount : 0; //银积分余额
          let consumeAmount = data.consume && data.consume.consumeAmount ? data.consume.consumeAmount : 0; //消费券余额

          let resell = data.resell; //转售
          let noResell = data.noResell ? data.noResell : 0;
          let freezeAmount = data.cash && data.cash.freezeAmount ? data.cash.freezeAmount : 0; //冻结金

          //1.0出入金
          let outCashMoney1 = this.list && this.list[0] && this.list[0].outCashMoney ? this.list[0].outCashMoney : 0;
          let inCashMoney1 = this.list && this.list[0] && this.list[0].inCashMoney ? this.list[0].inCashMoney : 0;

          let accumulatedIncome = brokerageAmount + cashAmount
            + goldAmount + silverAmount + consumeAmount + resell
            + freezeAmount + outCashMoney + outCashMoney1 + noResell
            - (inCashMoney + inCashMoney1);

          this.allList.forEach(item => {
            switch (item.name) {
              case '佣金余额':
                item.value = brokerageAmount;
                break;
              case '佣金总入':
                item.value = inBrokerageCashMoney;
                break;
              case '现金余额':
                item.value = cashAmount;
                break;
              case '累计收益':
                item.value = accumulatedIncome.toFixed(2);
                break;
              case '金积分余额':
                item.value = goldAmount;
                break;
              case '银积分余额':
                item.value = silverAmount;
                break;
              case '转售中(转卖后价格)':
                item.value = resell.resellPriceSum;
                break;
              case '转售中(买入价格)':
                item.value = resell.buyPriceSum;
                break;
              case '冻结金':
                item.value = freezeAmount;
                break;
              case '已付款未转卖':
                item.value = noResell;
                break;
              case '消费券余额':
                item.value = consumeAmount;
                break;
              default:
                break;
            }
          });
        }
        this.loading = false;
      });

      this.queryParams.userId = this.queryParams.userId;
      getOrderResellDetail(this.queryParams).then((response) => {
        if (response.code == 200) {
          let data = response.data;
          this.allList.forEach(item => {
            switch (item.name) {
              case '累计现金收益':
                item.value = data.allResellProfit;
                break;
              case '累计消费券收益':
                item.value = data.allConsumeAmount;
                break;
              default:
                break;
            }
          });
        }
        this.loading = false;
      });
    }
  }
}
</script>
<style lang="scss" scoped>
.page-view {
  margin-top: 10px;
  height: 50px;
}

.item-box {
  /* display: flex;
  flex-direction: row; */
  margin-top: 10px;
  margin-left: 10px;
}
.item {
  display: flex;
  flex-direction: row;
  .value {
    margin-left: 20px;
  }
}
</style>
